/**
 * 添加用户
 */
$(function(){
	var codelength=$('#operatorname').width();
	$('#operatorname').validatebox({
	    validType: {maxLength:[50]},
	    tipPosition:'top',
	    deltaX:codelength/4
	});
	$('#phone').validatebox({
	    validType: 'isMobile',
	    tipPosition:'top',
	    deltaX:codelength/4
	});
	$('#email').validatebox({
	    validType: 'email',
	    tipPosition:'top',
	    deltaX:codelength/4
	});
	$("#secrets").combobox({
		 required:true,
		 method:'get',
		 url:$Path+"/admin/secret/getCombobox",
		 valueField:'id',
		 textField:'text',
		 panelHeight:"auto",
		 onSelect:function(data){
			 $("#secretLevel").val(data.id);
		 }
	 })
	 var stadat=[{"id":"1","text":"启用"},{"id":"2","text":"停用"}]
	 $("#status").combobox({
		 required:true,
		 data:stadat,
		 panelHeight:"auto",
		 valueField:'id',
		 textField:'text'
	 })
	 $("#role").combobox({
		 required:true,
		 method:'get',
		 url:$Path+"/admin/role/getCombobox",
		 valueField:'id',
		 panelHeight:"auto",
		 textField:'text',
		 onSelect:function(data){
			 if(data.id!='role_03'){
				 $("#secrets").combobox({disabled:true});
			 }
			 if(data.id=='role_02'){
				 if(minLevel!=''){
					 $("#secrets").combobox('setValue',minLevel);
					 $("#secretLevel").val(minLevel);
				 }
			 }
			 else if(data.id=='role_01'){
				 if(maxLevel!=''){
					 $("#secrets").combobox('setValue',maxLevel);
					 $("#secretLevel").val(maxLevel);
				 }
			 }
			 else{
				 $("#secrets").combobox({disabled:false});
			 }
		 },
		 onLoadSuccess:function(data){
			 var id= $("#role").combobox('getValue')
			 if(id!='role_03'){
				 $("#secrets").combobox({disabled:true});
			 }
			 if(id=='role_02'){
				 if(minLevel!=''){
					 $("#secrets").combobox('setValue',minLevel);
					 $("#secretLevel").val(minLevel);
				 }
			 }
			 else if(id=='role_01'){
				 if(maxLevel!=''){
					 $("#secrets").combobox('setValue',maxLevel);
					 $("#secretLevel").val(maxLevel);
				 }
			 }
			 else{
				 $("#secretLevel").val($("#secrets").combobox('getValue'));
				 $("#secrets").combobox({disabled:false});
			 }
		 }
	 })
	//提交表单
	$("#submitBut").click(function(){
		$("#form_line").form('submit',{
			url:$Path+'/admin/operator/updtaeOperator',
			onSubmit:function(){
		        return $(this).form('validate');
		    },
		    dataType:'html',
		    success:function(data){
		    	var jdata=$.parseJSON(data); 
		        if(jdata.code==200){
		        	parent.$.messager.alert('成功','保存成功','info',function(){
		        		parent.$('#dlg').window('close');
		        		window.parent.refreshTab("用户管理");
		        	});
		        }
		        else{
		        	parent.$.messager.alert('失败',jdata.msg,'error');
		        }
		    }
		});
	})
})